﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Reflection;
using DbSharp.Framework.Common;

namespace DbSharp.Framework.DbObject
{
    [Obfuscation]
    public enum ArgumentDirection
    {         
        Input, 
        Output,  
        InputOutput,
        ReturnValue,
        AnonymousOutput,

        //this kind of argument will be replaced before query submit to server. 
        //e.g, select * from @some_table, here @some_table is clientside argument
        ClientSide
    }


    static class ArgumentDirectionHelper
    {
        public static ParameterDirection ConvertToParamDirection(ArgumentDirection argumentDirection)
        {
            ParameterDirection result;
            switch (argumentDirection)
            {
                case ArgumentDirection.Input:
                    result = ParameterDirection.Input;
                    break;
                case ArgumentDirection.Output:
                    result = ParameterDirection.Output;
                    break;
                case ArgumentDirection.InputOutput:
                    result = ParameterDirection.InputOutput;
                    break;
                case ArgumentDirection.ReturnValue:
                    result = ParameterDirection.ReturnValue;
                    break;
                case ArgumentDirection.AnonymousOutput:
                    throw new DbSharpException("ArgumentDirection.AnonymousOutput cannot be converted to ParameterDirection.");
                case ArgumentDirection.ClientSide:
                    throw new DbSharpException("ArgumentDirection.ClientSide cannot be converted to ParameterDirection.");
                default:
                    result = ParameterDirection.Input;
                    break;
            }
             
            return result;
        }

        public static ArgumentDirection ParseDirection(string directionString)
        {
            ArgumentDirection direction;
            switch (directionString.Trim().ToUpper())
            {
                case "OUT":
                case "OUTPUT":
                    {
                        direction = ArgumentDirection.Output;
                        break;
                    }
                case "INOUT":
                case "INPUTOUTPUT":
                    {
                        direction = ArgumentDirection.InputOutput;
                        break;
                    }
                case "RETURN":
                case "RETURNVALUE":
                    {
                        direction = ArgumentDirection.ReturnValue;
                        break;
                    }
                case "ANONYMOUSOUT":
                case "ANONYMOUSOUTPUT":
                    {
                        direction = ArgumentDirection.AnonymousOutput;
                        break;
                    }
                case "CLIENTSIDE":
                    {
                        direction = ArgumentDirection.ClientSide;
                        break;
                    }
                default:
                    {
                        direction = ArgumentDirection.Input;
                        break;
                    }
            }
            return direction;

        }
    }

}

